home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / gfx / 3d / irit50src.lha / irit5 / include / triv_lib.h < prev   
Encoding:
C/C++ Source or Header  |  1995-03-15  |  8.7 KB  |  252 lines

  1. /******************************************************************************
  2. * Triv_lib.h - header file for the TRIV library.                  *
  3. * This header is also the interface header to the world.              *
  4. *******************************************************************************
  5. * Written by Gershon Elber, Sep. 94.                          *
  6. ******************************************************************************/
  7.  
  8. #ifndef TRIV_LIB_H
  9. #define TRIV_LIB_H
  10.  
  11. #include <stdio.h>
  12. #include "irit_sm.h"
  13. #include "imalloc.h"
  14. #include "miscattr.h"
  15. #include "genmat.h"
  16. #include "cagd_lib.h"
  17. #include "symb_lib.h"
  18.  
  19. typedef CagdRType TrivPType[4];
  20. typedef CagdRType TrivVType[4];
  21. typedef CagdRType TrivUVWType[3];
  22. typedef CagdRType TrivPlaneType[5];
  23.  
  24. typedef enum {
  25.     TRIV_ERR_DIR_NOT_VALID,
  26.     TRIV_ERR_UNDEF_CRV,
  27.     TRIV_ERR_UNDEF_SRF,
  28.     TRIV_ERR_UNDEF_TRIVAR,
  29.     TRIV_ERR_UNDEF_GEOM,
  30.     TRIV_ERR_RATIONAL_NO_SUPPORT,
  31.     TRIV_ERR_WRONG_ORDER,
  32.     TRIV_ERR_KNOT_NOT_ORDERED,
  33.     TRIV_ERR_NUM_KNOT_MISMATCH,
  34.     TRIV_ERR_INDEX_NOT_IN_MESH,
  35.     TRIV_ERR_POWER_NO_SUPPORT,
  36.     TRIV_ERR_WRONG_DOMAIN,
  37.     TRIV_ERR_DIR_NOT_CONST_UVW,
  38.     TRIV_ERR_SCALAR_PT_EXPECTED,
  39.     TRIV_ERR_NO_CLOSED_POLYGON,
  40.     TRIV_ERR_TWO_INTERSECTIONS,
  41.     TRIV_ERR_NO_MATCH_PAIR,
  42.     TRIV_ERR_2_OR_4_INTERS,
  43.     TRIV_ERR_FAIL_FIND_PT,
  44.  
  45.     TRIV_ERR_UNDEFINE_ERR
  46. } TrivFatalErrorType;
  47.  
  48. typedef enum {
  49.     TRIV_UNDEF_TYPE = 1220,
  50.     TRIV_TVBEZIER_TYPE,
  51.     TRIV_TVBSPLINE_TYPE
  52. } TrivGeomType;
  53.  
  54. typedef enum {
  55.     TRIV_NO_DIR = CAGD_NO_DIR,
  56.     TRIV_CONST_U_DIR = CAGD_CONST_U_DIR,
  57.     TRIV_CONST_V_DIR = CAGD_CONST_V_DIR,
  58.     TRIV_CONST_W_DIR,
  59.     TRIV_END_DIR
  60. } TrivTVDirType;
  61. #define TRIV_PREV_DIR(Dir) (((int) Dir) + 1 > ((int) TRIV_CONST_W_DIR) ? \
  62.             TRIV_CONST_U_DIR : (TrivTVDirType) ((int) Dir) + 1)
  63. #define TRIV_NEXT_DIR(Dir) (((int) Dir) - 1 < ((int) TRIV_CONST_U_DIR) ? \
  64.             TRIV_CONST_W_DIR : (TrivTVDirType) ((int) Dir) - 1)
  65.  
  66. typedef struct TrivTriangleStruct {
  67.     struct TrivTriangleStruct *Pnext;
  68.     struct IPAttributeStruct *Attr;
  69.     struct {
  70.     CagdPType Pt;
  71.     CagdVType Nrml;
  72.     TrivUVWType UVW;
  73.     } T[3];
  74. } TrivTriangleStruct;
  75.  
  76. typedef struct TrivTVStruct {
  77.     struct TrivTVStruct *Pnext;
  78.     struct IPAttributeStruct *Attr;
  79.     TrivGeomType GType;
  80.     CagdPointType PType;
  81.     int ULength, VLength, WLength;/* Mesh size in tri-variate tensor product.*/
  82.     int UVPlane;      /* Should equal ULength * VLength for fast access. */
  83.     int UOrder, VOrder, WOrder;       /* Order in trivariate (Bspline only). */
  84.     CagdBType UPeriodic, VPeriodic, WPeriodic;    /* Valid only for Bspline. */
  85.     CagdRType *Points[CAGD_MAX_PT_SIZE];     /* Pointer on each axis vector. */
  86.     CagdRType *UKnotVector, *VKnotVector, *WKnotVector;
  87. } TrivTVStruct;
  88.  
  89. #define TRIV_IS_BEZIER_TV(TV)        (TV -> GType == TRIV_TVBEZIER_TYPE)
  90. #define TRIV_IS_BSPLINE_TV(TV)        (TV -> GType == TRIV_TVBSPLINE_TYPE)
  91.  
  92. #define TRIV_IS_RATIONAL_TV(TV)        CAGD_IS_RATIONAL_PT(TV -> PType)
  93.  
  94. /******************************************************************************
  95. *           +-----------------------+                          *
  96. *       W  /                       /|                          *
  97. *      /  /                       / |                          *
  98. *     /  /    U -->         /  |        The mesh is ordered raw after raw *
  99. *       +-----------------------+   |    or the increments along U are 1 while *
  100. *   V | |P0                 Pi-1|   +    the increment along V is full raw.    *
  101. *     v    |Pi                P2i-1|  /        Once a full UV plane is complete  *
  102. *    |            | /    W is incremented by 1.              *
  103. *    |Pn-i            Pn-1|/          To encapsulate it, NEXTU/V/W are  *
  104. *    +-----------------------+    defined below.                  *
  105. ******************************************************************************/
  106. #define TRIV_NEXT_U(TV)            (1)
  107. #define TRIV_NEXT_V(TV)            (TV -> ULength)
  108. #define TRIV_NEXT_W(TV)            (TV -> UVPlane)
  109. #define TRIV_MESH_UVW(TV, i, j, k)    ((i) + (TV -> ULength) * (j) + (TV -> UVPlane) * (k))
  110.  
  111. /* If a trivariate is periodic, the control polygon/mesh should warp up.     */
  112. /* Length does hold the real allocated length but the virtual periodic       */
  113. /* length is a little larger. Note allocated KV's are larger.                */
  114. #define TRIV_TV_UPT_LST_LEN(TV)    ((TV) -> ULength + \
  115.                  ((TV) -> UPeriodic ? (TV) -> UOrder - 1 : 0))
  116. #define TRIV_TV_VPT_LST_LEN(TV)    ((TV) -> VLength + \
  117.                  ((TV) -> VPeriodic ? (TV) -> VOrder - 1 : 0))
  118. #define TRIV_TV_WPT_LST_LEN(TV)    ((TV) -> WLength + \
  119.                  ((TV) -> WPeriodic ? (TV) -> WOrder - 1 : 0))
  120. #define TRIV_IS_UPERIODIC_TV(TV)    ((TV) -> UPeriodic)
  121. #define TRIV_IS_VPERIODIC_TV(TV)    ((TV) -> VPeriodic)
  122. #define TRIV_IS_WPERIODIC_TV(TV)    ((TV) -> WPeriodic)
  123. #define TRIV_IS_PERIODIC_TV(TV)    (CAGD_IS_UPERIODIC_TV(TV) || \
  124.                  CAGD_IS_VPERIODIC_TV(TV) || \
  125.                  CAGD_IS_WPERIODIC_TV(TV))
  126.  
  127. #if defined(__cplusplus) || defined(c_plusplus)
  128. extern "C" {
  129. #endif
  130.  
  131. /******************************************************************************
  132. * General routines of the Triv library:                          *
  133. ******************************************************************************/
  134. TrivTVStruct *TrivTVNew(TrivGeomType GType,
  135.             CagdPointType PType,
  136.             int ULength,
  137.             int VLength,
  138.             int WLength);
  139. TrivTVStruct *TrivBspTVNew(int ULength,
  140.                int VLength,
  141.                int WLength,
  142.                int UOrder,
  143.                int VOrder,
  144.                int WOrder,
  145.                CagdPointType PType);
  146. TrivTVStruct *TrivBzrTVNew(int ULength,
  147.                int VLength,
  148.                int WLength,
  149.                CagdPointType PType);
  150. TrivTVStruct *TrivTVCopy(TrivTVStruct *TV);
  151. TrivTVStruct *TrivTVCopyList(TrivTVStruct *TVList);
  152. void TrivTVFree(TrivTVStruct *TV);
  153. void TrivTVFreeList(TrivTVStruct *TVList);
  154.  
  155. TrivTriangleStruct *TrivTriangleNew(void);
  156. TrivTriangleStruct *TrivTriangleCopy(TrivTriangleStruct *Triangle);
  157. TrivTriangleStruct *TrivTriangleCopyList(TrivTriangleStruct *TriangleList);
  158. void TrivTriangleFree(TrivTriangleStruct *Triangle);
  159. void TrivTriangleFreeList(TrivTriangleStruct *TriangleList);
  160.  
  161. TrivTVStruct *TrivCnvrtBezier2BsplineTV(TrivTVStruct *TV);
  162.  
  163. void TrivTVTransform(TrivTVStruct *TV, CagdRType *Translate, CagdRType Scale);
  164. void TrivTVMatTransform(TrivTVStruct *TV, CagdMType Mat);
  165.  
  166. TrivTVStruct *TrivCoerceTVTo(TrivTVStruct *TV, CagdPointType PType);
  167.  
  168. void TrivTVDomain(TrivTVStruct *TV,
  169.           CagdRType *UMin,
  170.           CagdRType *UMax,
  171.           CagdRType *VMin,
  172.           CagdRType *VMax,
  173.           CagdRType *WMin,
  174.           CagdRType *WMax);
  175. CagdBType TrivParamInDomain(TrivTVStruct *TV,
  176.                 CagdRType t,
  177.                 TrivTVDirType Dir);
  178. CagdBType TrivParamsInDomain(TrivTVStruct *TV,
  179.                  CagdRType u,
  180.                  CagdRType v,
  181.                  CagdRType w);
  182.  
  183. CagdRType *TrivTVEval(TrivTVStruct *TV,
  184.               CagdRType u,
  185.               CagdRType v,
  186.               CagdRType w);
  187. CagdRType *TrivTVEval2(TrivTVStruct *TV,
  188.                CagdRType u,
  189.                CagdRType v,
  190.                CagdRType w);
  191. CagdSrfStruct *TrivSrfFromTV(TrivTVStruct *TV,
  192.                  CagdRType t,
  193.                  TrivTVDirType Dir);
  194. CagdSrfStruct *TrivSrfFromMesh(TrivTVStruct *TV,
  195.                    int Index,
  196.                    TrivTVDirType Dir);
  197. void TrivSrfToMesh(CagdSrfStruct *Srf,
  198.            int Index,
  199.            TrivTVDirType Dir,
  200.            TrivTVStruct *TV);
  201. TrivTVStruct *TrivTVRegionFromTV(TrivTVStruct *TV,
  202.                  CagdRType t1,
  203.                  CagdRType t2,
  204.                  TrivTVDirType Dir);
  205. TrivTVStruct *TrivTVRefineAtParams(TrivTVStruct *TV,
  206.                    TrivTVDirType Dir,
  207.                    CagdBType Replace,
  208.                    CagdRType *t,
  209.                    int n);
  210. TrivTVStruct *TrivBspTVKnotInsertNDiff(TrivTVStruct *TV,
  211.                        TrivTVDirType Dir,
  212.                        int Replace,
  213.                        CagdRType *t,
  214.                        int n);
  215. TrivTVStruct *TrivTVDerive(TrivTVStruct *TV, TrivTVDirType Dir);
  216. TrivTVStruct *TrivBzrTVDerive(TrivTVStruct *TV, TrivTVDirType Dir);
  217. TrivTVStruct *TrivBspTVDerive(TrivTVStruct *TV, TrivTVDirType Dir);
  218. TrivTVStruct *TrivTVDerive(TrivTVStruct *TV, TrivTVDirType Dir);
  219. TrivTVStruct *TrivTVSubdivAtParam(TrivTVStruct *TV,
  220.                   CagdRType t,
  221.                   TrivTVDirType Dir);
  222. TrivTVStruct *TrivTVDegreeRaise(TrivTVStruct *TV, TrivTVDirType Dir);
  223. TrivTVStruct *TrivBspTVDegreeRaise(TrivTVStruct *TV, TrivTVDirType Dir);
  224. TrivTVStruct *TrivBzrTVDegreeRaise(TrivTVStruct *TV, TrivTVDirType Dir);
  225. CagdBType TrivMakeTVsCompatible(TrivTVStruct **TV1,
  226.                 TrivTVStruct **TV2,
  227.                 CagdBType SameUOrder,
  228.                 CagdBType SameVOrder,
  229.                 CagdBType SameWOrder,
  230.                 CagdBType SameUKV,
  231.                 CagdBType SameVKV,
  232.                 CagdBType SameWKV);
  233. void TrivTVBBox(TrivTVStruct *Trivar, CagdBBoxStruct *BBox);
  234. void TrivTVListBBox(TrivTVStruct *TVs, CagdBBoxStruct *BBox);
  235. CagdPolylineStruct *TrivTV2CtrlMesh(TrivTVStruct *Trivar);
  236. TrivTVStruct *TrivInterpTrivar(TrivTVStruct *TV);
  237. TrivTVStruct *TrivTVFromSrfs(CagdSrfStruct *SrfList, int OtherOrder);
  238.  
  239. void TrivDbg(void *Obj);
  240.  
  241. /******************************************************************************
  242. * Error handling.                                  *
  243. ******************************************************************************/
  244. void TrivFatalError(TrivFatalErrorType ErrID);
  245. char *TrivDescribeError(TrivFatalErrorType ErrID);
  246.  
  247. #if defined(__cplusplus) || defined(c_plusplus)
  248. }
  249. #endif
  250.  
  251. #endif /* TRIV_LIB_H */
  252.